@extends('admin.master')

@section('css')
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <style>

        .file-input {
            margin: 10px 50px;
            position: relative;
            left: 46px;
        }

        .file-caption {
            margin-top: 5px;
            height: 36px;
        }
        .form-inline {
            margin-bottom: 20px;
        }

        .form-inline label {
            font-weight: bold;
            margin-right: 10px;
        }
    </style>
@stop


@section('content')
<table class="table table-bordered">
    <caption>商品列表</caption>
    <thead>
        <tr>
            <th>名称</th>
            <th>类型</th>
            <th>价格</th>
            <th>描述</th>
            <th>数量</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @foreach($goods as $item)
        <tr>
            <td>{{$item->name}}</td>
            <td>{{$item->type}}</td>
            <td>{{$item->cost}}</td>
            <td>{{$item->descript}}</td>
            <td>{{$item->num}}</td>
            <td><img style="width:30px;height:30px;" src="/storage/{{$item->img}}"></td>
            <td>
                <button  class="deletedGoods btn btn-info" value="{{$item->id}}">删除</button>
                <a  class="detailGoods btn btn-info" value="{{$item->id}}" href="{{url('/admin/goods/details')}}?id={{$item->id}}">详情</a>
                <a  class="updateGoods btn btn-info" value="{{$item->id}}" href="{{url('/admin/goods/updates')}}?id={{$item->id}}">修改</a>
            </td>
        </tr>
        @endforeach
    </tbody>
</table>
        {!! $goods->links() !!}
<script type="text/javascript">
// 删除商品
    $('.deletedGoods').click(function(){  
            // $(this).parent().parent().remove();
        var ids = $(this).attr("value");   
        var deleteds = $(this).parent().parent(); 

        var deleteds = confirm("是否确定删除");
        if (deleteds == true){
            $.ajax({
                url: './deleted',
                type: "post",
                data: {id:ids},
                success: function(res){
                    console.log(res);   
                    if(res == "true"){
                        deleteds.remove();
                        alert("删除成功");
                    }else {
                        alert("删除失败");
                    }
                }
            })      
        }
    }); 
</script>

@stop
@section('javascript')
    <script>
        $('document').ready(function () {
            $('.toggleswitch').bootstrapToggle();
        });
    </script>
    
    <script src="/js/tinymce.min.js"></script>
    <script src="/js/voyager_tinymce.js"></script>
@stop